import pandas as pd
df1 = pd.DataFrame({'key': ['a', 'b', 'c', 'd'], 'value1': [1, 2, 3, 4]})
df2 = pd.DataFrame({'key': ['a', 'd', 'e', 'f'], 'value2': [5, 6, 7, 8]})

# 左半连接
left_merge = pd.merge(df1, df2, on='key', how='left')
print("左半连接:")
print(left_merge)

# 右半连接
right_merge = pd.merge(df1, df2, on='key', how='right')
print("右半连接:")
print(right_merge)

# 反连接
outer_merge = pd.merge(df1, df2, on='key', how='outer', indicator=True).query('_merge != "both"')
print("反连接:")
print(outer_merge)
